'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE, BOOLEAN } = app.Sequelize;

  const Instore = app.model.define('instore', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    billNo: { type: STRING(30), unique: true, field: 'billNo' },
    goods_id: { type: STRING(36), unique: true },
    store_id: { type: INTEGER },
    loading_id: { type: INTEGER, comment: '车辆装卸记录' },
    // carno: { type: STRING(30), comment: '车牌号' },
    // checkno: { type: STRING(30), comment: '核放单号' },
    // WareHouseBillCode: { type: STRING(30), comment: '报关申请单号', field: 'WareHouseBillCode' },
    corp_id: { type: INTEGER, comment: '仓库使用公司' },
    owner: { type: STRING(30), comment: '创建者' },
    swner: { type: STRING(30), comment: '审核者' },
    sdate: DATE,

    description: STRING(200),
    status: STRING(10),
    created_at: DATE,
    updated_at: DATE,
  });

  Instore.associate = function() {
    app.model.Wms.Business.Instore.belongsTo(app.model.Wms.Basic.Store, { foreignKey: 'store_id' });
    app.model.Wms.Business.Instore.belongsTo(app.model.Wms.Business.Storegoods, { foreignKey: 'goods_id' });
    app.model.Wms.Business.Instore.belongsTo(app.model.Wms.Basic.Corp, { foreignKey: 'corp_id' });
    app.model.Wms.Business.Instore.belongsTo(app.model.Wms.Business.Loading, { foreignKey: 'loading_id' });
  };

  return Instore;
};
